// pages/improveInformation/index.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    avatarUrl: "",
    userName: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    const avatarUrl = wx.getStorageSync("avatarUrl") || "";
    const userName = wx.getStorageSync("userName") || "";
    console.log(avatarUrl, userName, "avatarUrl, userName");
    this.setData({
      avatarUrl,
      userName,
    });
  },
  onChooseAvatar(e: any) {
    const { avatarUrl } = e.detail;
    this.setData({
      avatarUrl,
    });
    // wx.setStorageSync("avatarUrl", avatarUrl);
  },
  onInputChange(e: any) {
    console.log(e, "eee");
    const nickName = e.detail.value;
    this.setData({
      userName: nickName,
    });
    // wx.setStorageSync("userName", nickName);
  },
  nicknamereview(e) {
    console.log(e, "1111");
    const { pass } = e.detail;
    if (!pass) {
      wx.showToast({
        title: "昵称不合规",
        icon: "none",
      });
      this.setData({
        userName: "",
      });
    }
  },
  onSubmit() {
    const { avatarUrl, userName: nickName } = this.data;

    if (!avatarUrl) {
      wx.showToast({
        title: "请选择头像",
        icon: "none",
      });
      return;
    }
    if (!nickName) {
      wx.showToast({
        title: "请输入昵称",
        icon: "none",
      });
      return;
    }
    wx.setStorageSync("avatarUrl", avatarUrl);
    wx.setStorageSync("userName", nickName);
    // wx.navigateBack({
    //   delta: 1,
    // });
    console.log(avatarUrl, nickName, "avatarUrl, nickName");
    wx.switchTab({
      url: "/pages/personal-center/index",
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
